package guda.house.dal.dao.impl;

import guda.grape.autogen.common.BaseDAO;
import guda.house.dal.dao.UnitDAO;
import guda.house.dal.dataobject.UnitDO;
import guda.grape.autogen.common.page.BaseQuery;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class UnitDAOImpl extends BaseDAO implements UnitDAO {

    @Override
	public Long insert(UnitDO unit) {
	      try {
                return (Long) getSqlMapperW().insert("unit.insert",unit);
          } catch (Exception e) {
                throw new RuntimeException(e);
          }

	}

    @Override
	public UnitDO getUnitById(Long unitId) {
	    return (UnitDO)getSqlMapClientTemplate().queryForObject("unit.getUnitById", unitId);
	}

    @Override
	public boolean delUnitById(Long unitId) {
	    int num = 0;
        try {
            num = getSqlMapperW().delete("unit.delUnitById",unitId);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        if(num>0){
            return true;
        }else{
            return false;
        }
	}

    @Override
	public List<UnitDO> getUnitByIds(List idsList) {
        Map m = new HashMap();
        m.put("idsList",idsList);
		return getSqlMapClientTemplate().queryForList("unit.selectByIds", m);
	}

    @Override
	public void cleanAutoIncrement(Long unitId) {
	    try {
            getSqlMapperW().update("unit.cleanAutoIncrement",unitId);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
	}

    @Override
    public List<UnitDO> selectForPage(BaseQuery baseQuery) {
        return getSqlMapClientTemplate().queryForList("unit.selectForPage", baseQuery);
    }

    @Override
    public int countForPage(BaseQuery baseQuery) {
        return (Integer)getSqlMapClientTemplate().queryForObject("unit.countForPage",baseQuery);
    }

    @Override
    public void updateByIdSelective(UnitDO unit) {
        try {
            getSqlMapperW().update("unit.updateByIdSelective",unit);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

}

